package s02;

import base.Sample;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author wangpp
 */
public class SampleAopTest {
    public static void main(String[] args) {
        Sample sample = SampleAop.createInstance(Sample.class, new SampleAdvice() {
            @Override
            public Object before(Object obj, Method method, Object[] args, MethodProxy proxy) {
                System.out.println("========before=========");
                throw new RuntimeException("hello before exception");
//                return null;
            }

            @Override
            public Object after(Object obj, Method method, Object[] args, MethodProxy proxy, Object result) {
                System.out.println("========after=========");
                return result;
            }

            @Override
            public Object error(Object obj, Method method, Object[] args, MethodProxy proxy, Throwable e) {
                System.out.println("=============error=========");
                return null;
            }

            @Override
            public Object finallyHandle(Object obj, Method method, Object[] args, MethodProxy proxy, Object result) {
                System.out.println("==========finally========");
                return result;
            }
        });

        sample.test();
    }
}
